<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- 讲师介绍 -->
    <section class="container">
      <header class="comm-title">
        <h2 class="fl tac">
          <span class="c-333">讲师介绍</span>
        </h2>
      </header>
      <div class="t-infor-wrap">
        <!-- 讲师基本信息 -->
        <section class="fl t-infor-box c-desc-content">
          <div class="mt20 ml20">
            <el-row>
              <el-col :span="6">
                <!-- 讲师头像 -->
                <section class="t-infor-pic">
                  <img :src="teacher.avatar" :alt="teacher.name">
                </section>
              </el-col>
              <el-col :span="18">
                <h3 class="hLh30">
                  <!-- 讲师姓名 -->
                  <span class="fsize24 c-333">{{ teacher.name }}&nbsp;
                    <!-- 讲师头衔 -->
                    <span v-if="teacher.level === 1">初级讲师</span>
                    <span v-if="teacher.level === 2">中级讲师</span>
                    <span v-if="teacher.level === 3">高级讲师</span>
                    <span v-if="teacher.level === 4">首席讲师</span>
                  </span>
                </h3>
                <section class="mt10">
                  <!-- 授课风格 -->
                  <span class="t-tag-bg">{{ teacher.style }}</span>
                </section>
                <section class="t-infor-txt">
                  <!-- 讲师介绍 -->
                  <p class="mt20">{{ teacher.career }}</p>
                </section>
              </el-col>
            </el-row>
          </div>
        </section>
        <div class="clear"/>
      </div>
      <section class="mt30">
        <div>
          <header class="comm-title all-teacher-title c-course-content">
            <h2 class="fl tac">
              <span class="c-333">主讲课程</span>
            </h2>
            <section class="c-tab-title">
              <a href="javascript: void(0)">&nbsp;</a>
            </section>
          </header>
          <!-- 无数据提示-->
          <section v-if="courseList.length===0" class="no-data-wrap">
            <span class="c-666 fsize14 ml10 vam">暂时没有相关数据</span>
          </section>
          <!-- 课程列表-->
          <article class="comm-course-list">
            <ul class="of">
              <li v-for="course in courseList" :key="course.id">
                <div class="cc-l-wrap">
                  <section class="course-img">
                    <img :src="course.cover" class="img-responsive">
                    <div class="cc-mask">
                      <a :href="'/course/'+course.id" title="开始学习" target="_blank" class="comm-btn c-btn-1">开始学习</a>
                    </div>
                  </section>
                  <h3 class="hLh30 txtOf mt10">
                    <a
                      :href="'/course/'+course.id"
                      :title="course.title"
                      class="course-title fsize18 c-333"
                    >
                      {{ course.title }}
                    </a>
                  </h3>
                </div>
              </li>
            </ul>
            <div class="clear"/>
          </article>
        </div>
      </section>
    </section>
  </div>
</template>

<script>
import teacherApi from '~/api/teacher'

export default {
  // 使用同步调用
  async asyncData(page) {
    const response = await teacherApi.queryInfoById(page.route.params.id)
    return {
      teacher: response.data.teacher,
      courseList: response.data.courseList
    }
  }
}
</script>
